#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e4 + 10;
int a[N];
LL f[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		f[i] = f[i - 1] + (i -  1) * (a[i] - a[i - 1]);
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += f[i];
	}
	cout << ans * 2<< endl;
	return 0;
}